package com.test.graphsqltest.dao;

import com.test.graphsqltest.beans.Item;
import com.test.graphsqltest.beans.ItemList;
import com.test.graphsqltest.beans.Param;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * @Description: TODO
 * @author: wangming
 * @date: 2021年08月14日 22:29
 */
@Component
public class ItemDao {
    private static final Map<Long,Item> ITEM_MAP=new HashMap<>();

    static {
        ITEM_MAP.put(0L,Item
                .builder()
                .name("wangming")
                .code("233")
                .createTime(65656L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
        ITEM_MAP.put(1L,Item
                .builder()
                .name("wangming1")
                .code("23322")
                .createTime(656565L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
        ITEM_MAP.put(2L,Item
                .builder()
                .name("wangming2")
                .code("233222")
                .createTime(656511L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
    }

    public ItemList list(){
        ItemList itemList=new ItemList();
        itemList.setItemList(new ArrayList<>(ITEM_MAP.values()));
        itemList.setTotal(ITEM_MAP.size());
        return itemList;
    }

    public static void main(String[] args){

        Map<Integer,Item> ITEM_MAP=new HashMap<>();

        ITEM_MAP.put(0,Item
                .builder()
                .name("wangming")
                .code("233")
                .createTime(65656L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
        ITEM_MAP.put(1,Item
                .builder()
                .name("wangming1")
                .code("23322")
                .createTime(656565L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
        ITEM_MAP.put(2,Item
                .builder()
                .name("wangming2")
                .code("233222")
                .createTime(656511L)
                .searchDate(Calendar.getInstance().getTime())
                .build()
        );
        Item item=ITEM_MAP.get(1L);
        System.out.println(item);
    }

    public Item queryById(Long id){
        Item item= ITEM_MAP.get(id);
        return item;
    }

    public Item updateNameById(Param param){
        Item item=ITEM_MAP.get(param.getId());
        item.setName(param.getName());
        return item;
    }

    /**
    * @Description: TODO
    * @author: wangming
    * @date: 删除id，同时需要显示被删的item

    * @Return:
    */
    public Item deleteItem(Long id){
        Item item=ITEM_MAP.get(id);
        ITEM_MAP.remove(id);
        return item;
    }


   public void insert(String code,Long id){
       Item insert=Item.builder()
               .id(id)
               .code(code)
               .createTime(Calendar.getInstance().getTimeInMillis())
               .searchDate(Calendar.getInstance().getTime())
               .name(code+"name")
               .build();
       ITEM_MAP.put(3L,insert);
   }

}
